package com.gz.logistics.library.listener;

import com.gz.logistics.library.util.Constants;
import com.gz.logistics.library.util.CrashHandler;

import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 单订单 业务签收回调接口
 * author wanner1991
 */
public abstract class SingleOrderDeliveryStatusChangeListener extends BaseListener {
    private String TAG = SingleOrderDeliveryStatusChangeListener.class.getSimpleName();

    @Override
    public void onFailure(int statusCode, Header[] headers,
                          Throwable throwable, JSONObject errorResponse) {
        CrashHandler.e(throwable);
        CrashHandler.i(TAG, "onFailure");
        onResponseFailed();
    }

    @Override
    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
        try {
            int status = response.getInt(Constants.REQ_STATUS);
            String msg = response.getString(Constants.REQ_MSG);

            switch(status){
                case Constants.REQ_OK:
                    onResponseSuccess();
                    break;
                case Constants.REQ_SN_IS_EMPTY:
                case Constants.REQ_USEID_IS_EMPTY:
                case Constants.REQ_NO_SPECIFIC_THIS_ORDER:
                case Constants.REQ_THIS_ORDER_IS_EMPTY:
                case Constants.REQ_DELIVERY_SIGN_FAIL:
                    onResponseFailed();
                    break;
                case Constants.REQ_HAS_NOT_SIGN_LOGISTICS:
                    onHasNotSignLogistic();
                    break;
                default:
                    onResponseFailed();
                    break;
            }

        } catch (JSONException e) {
            onFailure(statusCode, headers, e, new JSONObject());
        }
    }

    /**
     * 该订单还未 经过物流确认
     */
    public abstract void onHasNotSignLogistic();

    @Override
    public void onOffline() {

    }

    @Override
    public void onNoMoreData() {

    }
    public abstract void onResponseSuccess();
}
